----------------------------------------------------------------------------------
-- Company: 	Grand Valley State University
-- Engineer: 	Jeff VanOss
-- 
-- Create Date:    18:27:37 02/25/2010 
-- Design Name: 
-- Module Name:    ButtonDebounce - Behavioral 
-- Project Name:	Program 2: Tilt Maze 
-- Target Devices: Nexys2
-- Tool versions: 
-- Description: This logic will debounce a button. The button must be held for
--						about 100ms before the output is set high.
--
-- Dependencies: 
--
-- Revision: 
-- Revision 0.01 - File Created
-- Additional Comments: This code is modeled heavily from Dr. Sterians code on
--								page 60 of the Winter 2010 EGR 426 Course Pack
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity ButtonDebounce is
    Port ( Bin : in  STD_LOGIC;
           clk : in  STD_LOGIC;
           Bout : out  STD_LOGIC);
end ButtonDebounce;

architecture Behavioral of ButtonDebounce is
	signal shift : STD_LOGIC_VECTOR(4 downto 0);
begin
	process(clk, Bin, shift) begin
		--standard shift register, move every value down one and add the new button value to the ed
		if(rising_edge(clk)) then
			shift(3 downto 0) <= shift(4 downto 1);
			shift(4) <= not Bin;
		end if;
		
		--if the entire shift register is 0, then the button has been debounced
		if(shift = "00000") then
			Bout <= '1';
		else
			Bout <= '0';
		end if;
	end process;
end Behavioral;

